/*
 * Accordion.fx
 *
 * Created on Mar 1, 2010, 6:36:28 PM
 */
package com.gpsbuddy.components;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;

/**
 * @author jonycus
 */
public class Accordion extends CustomNode {

    public var items: AccordionItem[];
    public var itemHeight: Number;
    public var itemWidth: Number;
    public var itemSpacing:Number = 0;
    public var height:Number;
    var group = Group {
                content: [items]
            }

    override protected function create(): Node {
        var hasOpened: Boolean = false;
        for (item: AccordionItem in items) {
            item.owner = this;
            item.height = itemHeight;
            item.width = itemWidth;
            item.index = indexof item;
            item.spacing = itemSpacing;
            if (hasOpened) {
                item.layoutY = height - ((sizeof items - indexof item)*(item.height+itemSpacing) );
                item.contentGroup.visible = false;
            } else if (item.opened) {
                hasOpened = true;
                item.layoutY = indexof item * (item.height + itemSpacing);
            } else {
                item.layoutY = indexof item * (item.height + itemSpacing);
                item.contentGroup.visible = false;
            }
        }
        return group;
    }

}
